import InteractiveBase from "../../../LevelCommon/InteractiveBase";
import LevelBaseControl from "../../../LevelCommon/LevelBaseControl";
import { GamePropData } from "../../../Data/GamePropData";
import EnumData from "../../../../Enum/EnumData";
import GamePanel from "../../../Panel/GamePanel";

export default class GasFire extends InteractiveBase {
    /** 需要烧的道具id*/
    public needFirePropId: number;
    /** 烧后获得的道具*/
    public getPropId: number;
    /** 要烧的道具 放的位置*/
    private firePos: Laya.Sprite3D;
    private levelControl: LevelBaseControl;
    private firePropObj: Laya.Sprite3D;

    onStart() {
        this.firePos = this.owner.getChildByName("firePos") as Laya.Sprite3D;
        this.levelControl = window.gameFacade.LevelMng.GetCurLevelControl();
    }
    protected InteractiveLogic(): boolean {
        /** 判断有没有选择对应的道具*/
        if (this.levelControl.IsSelectProp(this.needFirePropId)) {
            this.levelControl.UseCurProp();
            let needFireProp: GamePropData = window.gameFacade.ConfigMng.GetGamePropDataById(this.needFirePropId);
            /** 把道具 放在火焰上烧 烧完给新道具*/
            let firePropPre: Laya.Sprite3D = window.gameFacade.SceneMng.GamePropObjPrefabRoot.GetGameProObjByRenderPath(needFireProp.renderPath);
            this.firePropObj = Laya.Sprite3D.instantiate(firePropPre, this.firePos);
            this.firePropObj.layer = 4;
            this.firePropObj.active = true;
            this.firePropObj.transform.localPosition = new Laya.Vector3(0, 0, 0);
            this.firePropObj.transform.localRotationEuler = new Laya.Vector3(0,0,0);
            this.firePropObj.transform.localScale = new Laya.Vector3(1.5,1.5,1.5);
            /** 烧完前不能有ui操作  创建一个遮罩*/
            let gamePanel = window.gameFacade.SceneMng.GetPanelById(EnumData.EnumPanelType.GamePanel) as GamePanel;
            gamePanel.ShowMaskImageAndAutoHide(2000, this, this.GetNewProp)
        }
        return true;
    }

    /** 获得新道具*/
    private GetNewProp(): void {
        this.firePropObj.destroy();
        let newPropData: GamePropData = window.gameFacade.ConfigMng.GetGamePropDataById(this.getPropId);
        this.levelControl.GetGameProp(newPropData);
    }
}